package com.lagou.demo03.util;

import java.sql.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DbUtil {
    private static String jdbcName;//用于描述驱动信息
    private static String dbUrl;//用于描述url信息
    private static String dbUsername;//用于描述用户名信息
    private static String dbpassword;//用于描述密码信息

    static {
        jdbcName="com.mysql.jdbc.Driver";
        dbUrl = "jdbc:mysql://localhost:3306/db_web";
        dbUsername = "root";
        dbpassword = "123456";
        try {
            Class.forName(jdbcName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnection() throws SQLException {
        Connection con = DriverManager.getConnection(dbUrl,dbUsername,dbpassword);
        return con;
    }

    public static void closeResource(Connection con, PreparedStatement preparedStatement) throws SQLException {
        if(null!=con){
            con.close();
        }if(null!=preparedStatement){
            preparedStatement.close();
        }
    }
}
